<link rel="stylesheet" href="{$Think.const.HOME_CSS}input.css">
<style>
	.head {
		width: 100%;
		text-align: center;
		margin-top: 30px;
	}
	table {
		width: 600px;
		border: 1px solid #ddd;
		margin: 20px auto;
	}
	td {
		border: 1px solid #ddd;
		padding: 6px 8px;
		height: 30px;
		line-height: 30px;
		text-align: center;
		color: #336699;
	}
	td input[type="text"] {
		width: 100%;
		border: 1px solid #eee;
		color: #ff0000;
		padding: 6px 8px;
		font-size: 14px;
		text-align: center;
		-webkit-box-sizing: border-box;
		-moz-box-sizing: border-box;
		box-sizing: border-box;
	}
	.tips {
		text-align: center;
		line-height: 30px;
		font-size: 16px;
		font-weight: 700;
		color: #339933;
	}
	#loading {
		width: 50px;
		height: 50px;
		background: #fff url({$Think.const.HOME_IMG}loading.gif) no-repeat scroll center center;
		border: 1px solid #ddd;
		border-radius: 5px;
		box-shadow: 2px 1px 1px #888;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99999;
		display: none;
	}
	#mask {
		width: 100%;
		height: 100%;
		background-color: rgba(255,255,255,0.1);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99998;
		display: none;
	}
</style>
<ul class="breadcrumb clearfix">
	<span>当前位置：</span>
	<li>
		<a href="{:U('Score/showList')}">
			学生成绩管理
		</a>
	</li>
	<li>
		&gt;
	</li>
	<li>
		学生成绩录入
	</li>
</ul>
<h1>学生成绩录入</h1>
<div id="cont">
	<div class="scoreAdd">
		<div class="head">
			班级:
			<select name="class_id" id="select-class">
				<foreach name="class_info" item="v">
					<option value="{$v.id}" {$v['id'] == $class_id ? 'selected' : ''}>{$v.name}</option>
				</foreach>
			</select>
			&nbsp;
			&nbsp;
			&nbsp;
			&nbsp;
			学期:
			<select name="term_id" id="select-term">
				<foreach name="term_info" item="v">
					<option value="{$v.id}" {$v['id'] == $term_id ? 'selected' : ''}>{$v.name}</option>
				</foreach>
			</select>
			&nbsp;
			&nbsp;
			&nbsp;
			&nbsp;
			课程:
			<select name="course_id" id="select-course">
				<foreach name="course_info" item="v">
					<option value="{$v.id}" {$v['id'] == $course_id ? 'selected' : ''}>{$v.name}</option>
				</foreach>
			</select>
		</div>
		<table>
			<tr>
				<volist name="student_info" id="v" mod="5">
					<td>
						{$v.name}
						<input type="text" class="score" name="score" value="{$v.id|getScore=###,$course_id,$term_id}" data-id="{$v.id}" placeHolder="成绩">
					</td>
					<eq name="mod" value="4"></tr><tr></eq>
				</volist>
			</tr>
		</table>
		<p class="tips">请在学生名字下方输入分数!</p>
		<div id="loading"></div>
		<div id="mask"></div>
	</div>
</div>
<script>
	$('#select-class').change(function(){
		window.location.href = "{:U('Score/addInfo')}" + '?class_id=' + $(this).val() + '&course_id=' + "{$course_id}" + "&term_id=" + "{$term_id}"; 
	});
	$('#select-term').change(function(){
		window.location.href = "{:U('Score/addInfo')}" + '?class_id=' + "{$class_id}" + '&course_id=' + "{$course_id}" + "&term_id=" + $(this).val(); 
	});
	$('#select-course').change(function(){
		window.location.href = "{:U('Score/addInfo')}" + '?class_id=' + "{$class_id}" + '&course_id=' + $(this).val() + "&term_id=" + "{$term_id}"; 
	});

	$('.score').blur(function(){
		if( $(this).val() != '' ) {
			var id = $(this).attr('data-id');
			var class_id = {$class_id};
			var course_id = {$course_id};
			var term_id = {$term_id};
			var score = $(this).val();

			$('#mask').show();
			$('#loading').css({
				'left' : ($(window).outerWidth() - $('#loading').outerWidth()) / 2,
				'top' : ($(window).outerHeight() - $('#loading').outerHeight()) / 2
			}).show();

			// 发送数据到后台
			$.post("{:U('Score/addInfo')}",{
				'student_id' : id,
				'class_id' : class_id,
				'course_id' : course_id,
				'term_id' : term_id,
				'score' : score
			},function(msg){
				if(msg != "SUCCESS") {
					alert('保存分数失败');
				}
				$("#loading").hide();
				$("#mask").hide();
			})

		}
	});

</script>
